
import modules from './modules'
import Vue from 'vue'
import Router from 'uni-simple-router'

Vue.use(Router)
const router = new Router({
    routes: [
			{
				path: '/pages/personal/index',
				name:"personal",
				meta:{verify:true}
			},
			{
				path: '/pages/home/index',
				name:"home",
				meta:{verify:true}
			},
			{
				path: '/pages/lifeRecord/index',
				name:"lifeRecord",
				meta:{verify:true}
			},
			{
				path: '/pages/personal/set',
				name:"set",
				meta:{verify:false}
			},
			{
				path: '/pages/personal/maintain',
				name:"maintain",
				meta:{verify:false}
			},
			{
				path: '/pages/personal/calendar',
				name:"calendar",
				meta:{verify:false}
			},
			{
				path: '/pages/login/index',
				name:"login",
				meta:{verify:false}
			},
			{
				path: '/pages/createPerson/index',
				name:"createPerson",
				meta:{verify:false}
			},
			{
				path: '/pages/personal/record',
				name:"record",
				meta:{verify:false}
			},
			{
				path: '/pages/personal/teacher',
				name:"teacher",
				meta:{verify:false}
			}
		]
});

//路由前置守卫
router.beforeEach((to, from, next) => {
	console.log(to.meta.verify)
	try {
	    const value = uni.getStorageSync('storage_key');
	    if(to.meta.verify){
	    	// next('/pages/personal/calendar')
			if(value){
				next()
			}
			else{
				next({
				    name: 'login',
				    params: {},
				    NAVTYPE: 'push'
				});
			}
	    }
	    else{
			next();
	    }
	} catch (e) {
	    // error
	}
})
// 路由后置守卫
router.afterEach((to, from) => {
})

export default router;